package com.etone.smartAudit.controller;

import com.etone.smartAudit.annotation.LoginAdmin;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.mapper.WorkOrderMapper;
import com.etone.smartAudit.service.WorkOrderRectifyService;
import com.etone.smartAudit.service.WorkOrderService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.workOrder.WorkCountReportVO;
import com.etone.smartAudit.vo.workOrder.WorkOrderRectifyVO;
import com.etone.smartAudit.vo.workOrder.WorkOrderVO;
import com.etone.smartAudit.vo.workOrder.WorkRectifyCountVO;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 张任豪
 */
@RestController
@AllArgsConstructor
@Api(tags = "风险整改&统计报表", value = "WorkOrderRectifyController")
public class WorkOrderRectifyController {

    private WorkOrderRectifyService workOrderRectifyService;

    @ApiOperation(value = "风险整改台账")
    @GetMapping("/workOrderRectify/list")
    public PagerVO<WorkOrderRectifyVO> list(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "项目名称") @RequestParam(required = false) String name,
            @ApiParam(value = "被审计单位") @RequestParam(required = false) String auditUnit,
            @ApiParam(value = "年份") @RequestParam(required = false) String year,
            @ApiParam(value = "开始日期") @RequestParam(required = false) Date startDate,
            @ApiParam(value = "结束日期") @RequestParam(required = false) Date endDate,
            @ApiParam(value = "工单状态(0未开始,1进行中,2办结)") @RequestParam(required = false) Integer status,
            @ApiParam(value = "整改是否超期(0否,1是)") @RequestParam(required = false) Integer isOverdue,
            @ApiParam(value = "关键字") @RequestParam(required = false) String keyword,
            @ApiParam(value = "开始审计金额") @RequestParam(required = false) Integer auditStart,
            @ApiParam(value = "结束审计金额") @RequestParam(required = false) Integer auditEnd,
            @ApiParam(value = "整改结果(0未整改，1部分整改，2完全整改)") @RequestParam(required = false) Integer rectifyResult
    ) {
        return workOrderRectifyService.listWorkOrderRectify(page,pageSize,name,auditUnit,year,startDate,endDate,status,isOverdue,keyword,auditStart,auditEnd,rectifyResult,admin);
    }

    @ApiOperation(value = "风险台账统计")
    @GetMapping("/workOrderRectify/rectifyCount")
    public WorkRectifyCountVO rectifyCount(@ApiIgnore @LoginAdmin Admin admin) {
        return workOrderRectifyService.rectifyCount(admin);
    }

    @ApiOperation(value = "手动统计地市级报表")
    @GetMapping("/workOrderRectify/countCity")
    public void countCity() {
        workOrderRectifyService.countCity();
    }
    @ApiOperation(value = "手动统计省公司报表")
    @GetMapping("/workOrderRectify/provinceCity")
    public void countProvince() {
        workOrderRectifyService.countProvince();
    }

    @ApiOperation(value = "手动统计省公司报表")
    @GetMapping("/workOrderRectify/countProject")
    public void countProject() {
        workOrderRectifyService.countProject();
    }

    @ApiOperation(value = "获取统计报表")
    @GetMapping("/workOrderRectify/getCountReport")
    public List<WorkCountReportVO> getCountReport(
            @ApiParam(value = "报表类型(1:地市纬度,2:省公司纬度,3:项目纬度)") @RequestParam(required = false,defaultValue = "1") Integer type,
            @ApiParam(value = "年份") @RequestParam(required = false) Integer year,
            @ApiParam(value = "地市") @RequestParam(required = false) String city,
            @ApiParam(value = "部门名称") @RequestParam(required = false) String department,
            @ApiParam(value = "项目名称") @RequestParam(required = false) String itemName
    ) {
        return workOrderRectifyService.getCountReport(type,year,city,department,itemName);
    }

    @ApiOperation(value = "地市统计报表导出")
    @GetMapping("/workOrderRectify/exportCityReport")
    public void exportProvinceReport(
            @ApiParam(value = "年份") @RequestParam(required = false) Integer year,
            HttpServletResponse response
    ) {
        workOrderRectifyService.exportCityReport(year,response);
    }

    @ApiOperation(value = "省公司统计报表导出")
    @GetMapping("/workOrderRectify/exportProvinceReport")
    public void exportProvinceReport(HttpServletResponse response) {
        workOrderRectifyService.exportProvinceReport(response);
    }

    @ApiOperation(value = "项目统计报表导出")
    @GetMapping("/workOrderRectify/exportProjectReport")
    public void exportProjectReport(
            @ApiParam(value = "年份") @RequestParam(required = false) Integer year,
            HttpServletResponse response) {
        workOrderRectifyService.exportProjectReport(year,response);
    }

    @ApiOperation(value = "获取省公司部门")
    @GetMapping("/workOrderRectify/getProvinceDept")
    public List<Map<String, Object>> getProvinceDept() {
         return workOrderRectifyService.getProvinceDept();
    }

}
